define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Message_detail, $stateParams, Auth, GoDialog, $sce, GoPage, $compile) {
		
		$scope.mail_id = $stateParams.mail_id;
		$scope.$on('$ionicView.afterEnter', function() {
			$scope.init_page();
			$scope.issue_type = Auth.get_loginInfo().issue_type;//1为买家  2为卖家
		}, false);

		// 初始化页面
		$scope.init_page = function(index, isInit, completeFlag) {
			var Infos = Auth.get_loginInfo();

			if(!Infos) {
				GoDialog.toast('未登录');
				GoPage.go_tabPage('home');
				return;
			}

			var param = {
				mail_id: $scope.mail_id,
				session: Infos.user_id
			}

			Message_detail.get_detail(param, function(res) {
				if(res.success != true) {
					GoDialog.toast(res.msg);
					return;
				}

				$scope.data = res.result;
				var html = "<div>" + $scope.data.content + "</div>";
				//html = $sce.trustAsHtml(html)
				setTimeout(function() {
					var result = $compile(html)($scope);
					document.getElementById("content").innerHTML = "";
					for(var i = 0; i < result.length; i++) {
						document.getElementById("content").appendChild(result[i]);
					}
				}, 300);
			});
		};

		//跳转企业视频
		$scope.gostar = function(id) {
			GoPage.go_states("stardetail", { "detail_id": id });
		};

		//删除站内信
		$scope.do_delete = function() {
			var param = {
				mail_id: $scope.mail_id
			}
			Message_detail.delete(param, function(res) {
				if (res.success) {
					GoDialog.toast("删除成功！");
					GoPage.go_states("t-message");//删除成功后，跳转要一览页面
				}else{
					GoDialog.toast(res.msg);
				}
			})
		}
		
		//确认删除
		$scope.confirmDel = function(){
			GoDialog.confirm("删除站内信","确定要删除吗？",function(){
				$scope.do_delete();
			})
		}
		


	}

	controller.$inject = ['$scope', 'Message_detail', '$stateParams', 'Auth', 'GoDialog', '$sce', 'GoPage', '$compile'];

	return app.registerController("message_detailctrl", controller);
});